# 编译.o文件
# CC = cc

# ROOTPATH=../..
# INCLUDE = -I./applications -I$(ROOTPATH)/inc
# LIB=-lpthread

# OBJ += $(patsubst %.c, %.o, $(wildcard applications/*.c))
# OBJ += $(patsubst %.c, %.o, $(wildcard $(ROOTPATH)/src/*.c))
# OBJ += $(patsubst %.c, %.o, $(wildcard $(ROOTPATH)/samples/*.c))

# CFLAGS = -O0 -g3 -Wall
# target = FlashDBLinuxDemo

# all:$(OBJ)
# 	$(CC) out/*.o -o $(target) $(LIB)
# 	mv $(target) out
# %.o:%.c
# 	$(CC) $(CFLAGS) -c $< -o $@ $(INCLUDE)
# 	mv $@ out
# clean:
# 	rm -rf out/*

# 编译.so文件
CC = cc

ROOTPATH = ../..
INCLUDE = -I./applications -I$(ROOTPATH)/inc
LIB = -lpthread

# 使用 out 目录存放所有的对象文件
OBJ_DIR = out

OBJ += $(patsubst %.c, $(OBJ_DIR)/%.o, $(wildcard applications/*.c))
OBJ += $(patsubst %.c, $(OBJ_DIR)/%.o, $(wildcard $(ROOTPATH)/src/*.c))
OBJ += $(patsubst %.c, $(OBJ_DIR)/%.o, $(wildcard $(ROOTPATH)/samples/*.c))

CFLAGS = -O0 -g3 -Wall -fPIC
LDFLAGS = -shared

target = libflashdb.so

all: $(target)

$(target): $(OBJ)
	$(CC) $(LDFLAGS) $(OBJ) -o $(target) $(LIB)
	mkdir -p $(OBJ_DIR)
	mv $(target) $(OBJ_DIR)

$(OBJ_DIR)/%.o: %.c
	@mkdir -p $(dir $@)
	$(CC) $(CFLAGS) -c $< -o $@ $(INCLUDE)

clean:
	rm -rf $(OBJ_DIR)/*


